package Chapter05.animal;

import java.util.*;

public class AttendanceSystem {
    private Map<String, Set<String>> attendanceMap;

    public AttendanceSystem() {
        attendanceMap = new HashMap<String, Set<String>>();
    }

    public void checkIn(String username, String date) {
        if (!attendanceMap.containsKey(username)) {
            attendanceMap.put(username, new HashSet<String>());
        }
        attendanceMap.get(username).add(date);
        System.out.println("Check-in successful for " + username + " on " + date + ".");
    }

    public void checkOut(String username, String date) {
        if (attendanceMap.containsKey(username)) {
            Set<String> dates = attendanceMap.get(username);
            if (dates.contains(date)) {
                dates.remove(date);
                System.out.println("Check-out successful for " + username + " on " + date + ".");
                return;
            }
        }
        System.out.println("No check-in record found for " + username + " on " + date + ".");
    }

    public static void main(String[] args) {
        AttendanceSystem attendanceSystem = new AttendanceSystem();
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.print("Enter username: ");
            String username = scanner.nextLine();
            System.out.print("Enter date (yyyy-mm-dd): ");
            String date = scanner.nextLine();
            System.out.print("Enter 'in' or 'out': ");
            String action = scanner.nextLine();
            if (action.equals("in")) {
                attendanceSystem.checkIn(username, date);
            } else if (action.equals("out")) {
                attendanceSystem.checkOut(username, date);
            } else {
                System.out.println("Invalid action.");
            }
        }
    }
}
